package com.gujiangbo.application.controller;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.gujiangbo.application.base.BaseOutVo;
import com.gujiangbo.application.manage.service.HttpNorthManageService;
import com.gujiangbo.application.req.UserInfoInVo;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author Administrator
 */
@RestController
public class UserManageController {

    private Log debugLog = LogFactory.getLog(UserManageController.class);

    @Autowired
    private HttpNorthManageService httpNorthManageService;

    private ObjectMapper objectMapper = new ObjectMapper();

    @RequestMapping(value = "/addUserInfo",method = RequestMethod.POST)
    public String addUserInfo(@RequestBody String requestBody, HttpServletRequest httpServletRequest){
        debugLog.info("获取请求消息:" + requestBody);
        BaseOutVo baseOutVo = new BaseOutVo();
        try{
            UserInfoInVo userInfoInVo = objectMapper.readValue(requestBody, UserInfoInVo.class);
            baseOutVo = httpNorthManageService.addUserInfo(userInfoInVo,httpServletRequest);
        }catch (Exception e){
            debugLog.error("userManage error,message="+e.getMessage().toString());
        }
        return JSONObject.toJSONString(baseOutVo);
    }


}
